<?php
	require(DIR_TEMPLATE . C('config_template')."/setting/setting.php" );
	$config_theme = C('config_theme');
	$display_mode = $config_theme['display_mode'];
	$category_product_row = isset($config_theme['category_product_row']) ?  $config_theme['category_product_row'] : 3;
	$span = floor(12 / $category_product_row);
?>
<?php echo $header; ?>

<div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
    	<?php echo $breadcrumb['separator']; ?>
    	<a itemprop="url" href="<?php echo $breadcrumb['href']; ?>">
    		<span itemprop="title"><?php echo $breadcrumb['text']; ?></span>
    	</a>
    </span>
    <?php } ?>
</div>
 
<div> 
<?php if ($SPAN[0]) { ?>
  <div class="span<?php echo $SPAN[0]; ?>">
    <?php echo $column_left; ?>
  </div>
<?php } ?>

<div class="span<?php echo $SPAN[1];?>">
<div id="content"><?php echo $content_top; ?>
  <h1><?php echo $heading_title; ?></h1>
  <?php if ($thumb || $description) { ?>
  <div class="category-info">
    <?php if ($thumb) { ?>
    <div class="image"><img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" /></div>
    <?php } ?>
    <?php if ($description) { ?>
    <?php echo $description; ?>
    <?php } ?>
  </div>
  <?php } ?>

  <?php if (isset($attributes)) {?>
  <div class="box attribute-filter hidden-phone">
	<ul>
	<?php foreach ($attributes as $attribute) { ?>
		<li>
			<dl>
				<dt><?php echo $attribute['name']?>:</dt>
				<?php foreach ($attribute['values'] as $k => $v) { ?>
				<?php if ($v['selected']) {?>
				<dd><a href="<?php echo $v['link'];?>" class="selected"><?php echo $v['value']; ?></a></dd>
				<?php } else { ?>
				<dd><a href="<?php echo $v['link'];?>"><?php echo $v['value']; ?></a></dd>
				<?php } ?>
				<?php } ?>
			</dl>
		</li>
	<?php } ?>
	</ul>
  </div>
  <?php } ?>
  
  <?php if ($products) { ?>
  <div class="product-filter hidden-phone">
    <div class="display">
    <span><?php echo $_['text_display']; ?></span>
    <span><?php echo $_['text_list']; ?> </span>
	<a onclick="display('grid');"><?php echo $_['text_grid']; ?></a>
	</div>

    <div class="sort"><span><?php echo $_['text_sort']; ?></span>
      <select onchange="location = this.value;">
        <?php foreach ($sorts as $sorts) { ?>
        <?php if ($sorts['value'] == $sort . '-' . $order) { ?>
        <option value="<?php echo $sorts['href']; ?>" selected="selected"><?php echo $sorts['text']; ?></option>
        <?php } else { ?>
        <option value="<?php echo $sorts['href']; ?>"><?php echo $sorts['text']; ?></option>
        <?php } ?>
        <?php } ?>
      </select>
    </div>

    <div class="limit"><span><?php echo $_['text_limit']; ?></span>
      <select onchange="location = this.value;">
        <?php foreach ($limits as $limits) { ?>
        <?php if ($limits['value'] == $limit) { ?>
        <option value="<?php echo $limits['href']; ?>" selected="selected"><?php echo $limits['text']; ?></option>
        <?php } else { ?>
        <option value="<?php echo $limits['href']; ?>"><?php echo $limits['text']; ?></option>
        <?php } ?>
        <?php } ?>
      </select>
    </div>
    <div class="product-compare"><a href="<?php echo U('product/compare'); ?>" id="compare-total"><?php echo $text_compare; ?></a></div>
  </div>
  <div class="pagination"><?php echo $pagination; ?></div>
  <div class="product-list">
    <div class="row-fluid">
    <?php foreach ($products as $i => $product) { ?>
	<?php if ($i > 0 && $i % $category_product_row ==0) { ?>
	</div><div class="row-fluid">
	<?php } ?>
    <div class="span<?php echo $span;?> product-block">
      <?php if ($product['thumb']) { ?>
      <div class="image">
	  <?php if($product['special'] ) {   ?>
		<span class="product-label-special label"><?php echo $_['text_sale']; ?></span>
	  <?php } ?>
	  <a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
      <?php } ?>
      <div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div>
      <div class="description"><?php echo $product['summary'] ?></div>
      <div class="rating"><img src="themes/<?php echo C('config_template');?>/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
	  <div class="group-item">
	  <div class="price-cart">
      <?php if ($product['price']) { ?>
      <div class="price">
        <?php if (!$product['special']) { ?>
        	<?php echo $product['price']; ?>
        <?php } else { ?>
        <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
        <?php } ?>
        <?php if ($product['tax']) { ?>
        <br />
        <span class="price-tax"><?php echo $_['text_tax']; ?> <?php echo $product['tax']; ?></span>
        <?php } ?>
      </div>
      <?php } ?>      
      <div class="cart">
        <input type="button" value="<?php echo $_['button_cart']; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
      </div>
	  </div>
	  </div>
     <div class="wishlist-compare">
		  <a class="wishlist" onclick="addToWishList('<?php echo $product['product_id']; ?>');" title="<?php echo $_['button_wishlist']; ?>"><?php echo $_['button_wishlist']; ?></a>
		  <a class="compare"  onclick="addToCompare('<?php echo $product['product_id']; ?>');" title="<?php echo $_['button_compare']; ?>"><?php echo $_['button_compare']; ?></a>
	 </div>
    </div>
    <?php } ?>
	</div>
  </div>
 <div class="product-filter hidden-phone">
    <div class="display"><b><?php echo $_['text_display']; ?></b> <?php echo $_['text_list']; ?> <b>/</b> <a onclick="display('grid');"><?php echo $_['text_grid']; ?></a></div>
   <div class="product-compare"><a href="<?php echo U('product/compare'); ?>" id="compare-total"><?php echo $text_compare; ?></a></div>
  </div>
   <div class="pagination"><?php echo $pagination; ?></div>
  <?php } else { ?>
  <div class="content"><?php echo $_['text_empty_result']; ?></div>
  <div class="buttons">
    <div class="right"><a href="<?php echo $continue; ?>" class="button"><?php echo $_['button_continue']; ?></a></div>
  </div>
  <?php } ?>
  <?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
function display(view) {
	if (view == 'list') {
		$('.product-grid').attr('class', 'product-list');

		$('.product-list div.product_block').each(function(index, element) {
			html  = '<div class="right">';
			html += '  <div class="cart">' + $(element).find('.cart').html() + '</div>';
			html += '  <div class="wishlist">' + $(element).find('.wishlist').html() + '</div>';
			html += '  <div class="compare">' + $(element).find('.compare').html() + '</div>';
			html += '</div>';			
			
			html += '<div class="left">';

			var image = $(element).find('.image').html();

			if (image != null) {
				html += '<div class="image">' + image + '</div>';
			}

			var price = $(element).find('.price').html();
			
			if (price != null) {
				html += '<div class="price">' + price  + '</div>';
			}
					
			html += '  <div class="name">' + $(element).find('.name').html() + '</div>';
			html += '  <div class="description">' + $(element).find('.description').html() + '</div>';
			
			var rating = $(element).find('.rating').html();

			if (rating != null) {
				html += '<div class="rating">' + rating + '</div>';
			}
				
			html += '</div>';


			$(element).html(html);
		});

		$('.display').html('<span style="float:left;"><?php echo $_['text_display']; ?></span> <a class="list active"><?php echo $_['text_list']; ?></a><a class="grid" onclick="display(\'grid\');"><?php echo $_['text_grid']; ?></a>');

		$.cookie('display', 'list');
	} else {
		$('.product-list').attr('class', 'product-grid');

		$('.product-grid  div.product_block').each(function(index, element) {
			html = '';

			var image = $(element).find('.image').html();

			if (image != null) {
				html += '<div class="image">' + image + '</div>';
			}

			html += '<div class="name">' + $(element).find('.name').html() + '</div>';
			html += '<div class="description">' + $(element).find('.description').html() + '</div>';

			var price = $(element).find('.price').html();

			if (price != null) {
				html += '<div class="price">' + price  + '</div>';
			}

			var rating = $(element).find('.rating').html();

			if (rating != null) {
				html += '<div class="rating">' + rating + '</div>';
			}

			html += '<div class="cart">' + $(element).find('.cart').html() + '</div>';
			html += '<div class="wishlist">' + $(element).find('.wishlist').html() + '</div>';
			html += '<div class="compare">' + $(element).find('.compare').html() + '</div>';

			$(element).html(html);
		});

		$('.display').html('<span style="float: left;"><?php echo $_['text_display']; ?></span> <a class="list" onclick="display(\'list\');"><?php echo $_['text_list']; ?></a> <a class="grid active"> <?php echo $_['text_grid']; ?></a>');

		$.cookie('display', 'grid');
	}
}

view = $.cookie('display');

if (view) {
	display(view);
} else {
	display('<?php echo $display_mode;?>');
}
//--></script>
</div>

<?php if ($SPAN[2]) { ?>
  <div class="span<?php echo $SPAN[2]; ?>">
    <?php echo $column_right; ?>
  </div>
<?php } ?>
</div>
<?php echo $footer; ?>